package com.resp;

import jakarta.servlet.ServletException;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
@WebServlet(urlPatterns = "/resp5",name = "resp5")
public class respond5 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 通过设置不同的响应头 来达到不同的效果
        File file = new File("E:\\Users\\wenze-zero\\Pictures\\1622633551699.jpg") ;
        ServletOutputStream outputStream = resp.getOutputStream();

        resp.setHeader("content-disposition" , "attachment;filename="+file.getName() );
        byte[] bytes = Files.readAllBytes(file.toPath());

        outputStream.write( bytes );
    }
}
